package org.atlantis.ymer;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.atlantis.ymer.event.ClientEventEmitter;
import org.atlantis.ymer.event.EventCallback;
import org.atlantis.ymer.event.ServerEventEmitter;

public class ChatExample {

	private ConcurrentMap<String, ClientEventEmitter> clients = new ConcurrentHashMap<String, ClientEventEmitter>();

	public void startYmer() throws Exception {
		YmerBootstrap ymer = new YmerBootstrap();
		ymer.getOptions().setConnectorServerPort(5656);
		final ServerEventEmitter emitter = ymer.start();
		emitter.on(ServerEventEmitter.AppTopic.CONNECT, new EventCallback<ClientEventEmitter>() {

			@Override
			public void process(ClientEventEmitter client) {
				System.out.println("A client connected. Id: " + client.getId());
				clients.put(client.getId(), client);
				// 当前聊天室人数
				emitter.emit("sys_number", "" + clients.size());
				// xxx加入聊天室提醒
				emitter.emit("sys_message", "");
			}
		});
	}

	public static void main(String[] args) {
	}
}
